/**
 * 1668. 最大重复子字符串
 * https://leetcode-cn.com/problems/maximum-repeating-substring/
 */
public class Solutions_1668 {
    public static void main(String[] args) {
//        String sequence = "ababc", word = "ab";  // output: 2
//        String sequence = "ababc", word = "ba";  // output: 1
//        String sequence = "ababc", word = "ac";  // output: 0
        String sequence = "aaabaaaabaaabaaaabaaaabaaaabaaaaba",	word = "aaaba";  // output: 5

        int result = maxRepeating(sequence, word);
        System.out.println(result);
    }

    public static int maxRepeating(String sequence, String word) {
        int res = 0;
        String temp = word;
        while (sequence.contains(temp)) {
            res ++;
            // 拼接后，再查询："aaaba" + "aaaba" = "aaabaaaaba"
            temp = temp + word;
        }
        return res;
    }
}
